using System;
using System.Collections.Generic;
using System.Linq;

using Csla;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.IoC;

using DemoApp.DataAccess;

namespace DemoApp.BusinessLayer 
{
  [Serializable]
  public partial class CslaFavoriteDerivedEdit : 
    CslaFavoriteEdit,
    IFavoriteDerived
  {
    #region [ Business Properties ]

    public static PropertyInfo<DateTime?> DateOfCreationPropertyInfo = RegisterProperty(new PropertyInfo<DateTime?>("DateOfCreation"));
    public DateTime? DateOfCreation 
    { 
      get
      {
        return GetProperty(DateOfCreationPropertyInfo);
      }
      set
      {
        LoadProperty(DateOfCreationPropertyInfo, value);
      }
    }

    public static PropertyInfo<CslaFavoriteEditCollection> SubFavoritesPropertyInfo = RegisterProperty(new PropertyInfo<CslaFavoriteEditCollection>("SubFavorites"));
    public CslaFavoriteEditCollection SubFavorites 
    { 
      get
      {
        return GetProperty(SubFavoritesPropertyInfo);
      }
      private set
      {
        LoadProperty(SubFavoritesPropertyInfo, value);
      }
    }

    #endregion [ Business Properties ]

    #region [ Validation Rules ]
    #endregion [ Validation Rules ]

    #region [ Authorization Rules ]
    #endregion [ Authorization Rules ]
	
    #region [ Factory Methods ]

    #region [ Root Factory Methods ]
    public static CslaFavoriteDerivedEdit New()
    {
      return DataPortal.Create<CslaFavoriteDerivedEdit>();
    }

    public static void Delete(FavoriteKey key)
    {
      DataPortal.Delete<FavoriteDerived>(new SingleCriteria<FavoriteDerived, FavoriteKey>(key));
    }

    public static void Delete(Guid UserId, Guid SubjectId)
    {
      Delete(new FavoriteKey { UserId = UserId, SubjectId = SubjectId });
    }
    #endregion [ Root Factory Methods ]

    #region [ Child Factory Methods ]
    internal static CslaFavoriteDerivedEdit NewChild()
    {
      return DataPortal.CreateChild<CslaFavoriteDerivedEdit>();
    }

    internal static CslaFavoriteDerivedEdit GetFavoriteDerivedEdit(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      if (data == null) throw new ArgumentNullException("data");
      if (loadSettings == null) throw new ArgumentNullException("loadSettings");
      CslaFavoriteDerivedEdit result = new CslaFavoriteDerivedEdit();
      result.FetchFavoriteDerived(data, loadSettings);
      result.MarkAsChild();
      return result;
    }
    #endregion [ Child Factory Methods ]

    private static int ForceInitField = 0;
    protected CslaFavoriteDerivedEdit() 
    {
      ForceInitField = 1;
    }
    #endregion [ Factory Methods ]

    #region [ Data Access ]

    #region [ Root Data Access ]
    protected override void DataPortal_Create()
    {
      base.DataPortal_Create();
    }

    [Transactional(TransactionalTypes.TransactionScope)]
    protected override void DataPortal_Insert()
    {
    }
    
    [Transactional(TransactionalTypes.TransactionScope)]
    protected override void DataPortal_Update()
    {
    }
    
    [Transactional(TransactionalTypes.TransactionScope)]
    protected override void DataPortal_DeleteSelf()
    {
      DataPortal_Delete(new SingleCriteria<FavoriteDerived, FavoriteKey>(new FavoriteKey { UserId = this.UserId, SubjectId = this.SubjectId }));
    }
    
    [Transactional(TransactionalTypes.TransactionScope)]
    private void DataPortal_Delete(SingleCriteria<FavoriteDerived, FavoriteKey> criteria)
    {
    }
    #endregion [ Root Data Access ]

    #region [ Child Data Access ]
    protected override void Child_Create()
    {
      base.Child_Create();
    }
    
    private void Child_Fetch(object childData)
    {
    }
    
    private void Child_Insert(object parent)
    {
    }
    
    private void Child_Update(object parent)
    {
    }
    
    private void Child_DeleteSelf(object parent)
    {
    }
    #endregion [ Child Data Access ]

    protected void FetchFavoriteDerived(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      FetchFavoriteDerivedData(data, loadSettings);
      FetchFavoriteDerivedChildren(data, loadSettings);
    }

    protected void FetchFavoriteDerivedData(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      base.FetchFavoriteData(data, loadSettings);
      this.DateOfCreation = data.DateOfCreation;
    }

    protected void FetchFavoriteDerivedChildren(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      base.FetchFavoriteData(data, loadSettings);
      if (loadSettings.Inclusion.IncludeSubFavorites)
        this.SubFavorites = CslaFavoriteEditCollection.GetFavoriteEditCollection(data.SubFavorites, loadSettings.Inclusion.IncludedSubFavoritesSettings);
    }
    #endregion [ Data Access ]

    #region [ Explicit IFavoriteDerived implementation ]

    DateTime? IFavoriteDerived.DateOfCreation
    {
      get { return this.DateOfCreation; }
      set
      {
        this.DateOfCreation = value;
      }
    }

    IBusinessObjectCollection<IFavorite> IFavoriteDerived.SubFavorites
    { 
      get
      {
        return this.SubFavorites;
      }
    }


    bool IBusinessObject.IsReadonly
    {
      get { return false; }
    }

    bool IBusinessObject.IsDirty
    {
      get { return this.IsDirty; }
    }

    #endregion [ Explicit IFavoriteDerived implementation ]
  }
}
